package game;

import javax.swing.*;

public class GameFrame extends JFrame {
    public GameFrame(int difficulty) {
        setTitle("极限闪避60秒");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setResizable(false);

        GamePanel panel = new GamePanel(this, difficulty);
        add(panel);
        pack();
        setLocationRelativeTo(null);
        setVisible(true);
    }

    // 游戏失败或成功后调用此方法
    public void askRestart() {
        int option = JOptionPane.showConfirmDialog(
                this,
                "是否重新开始？",
                "游戏结束",
                JOptionPane.YES_NO_OPTION
        );

        if (option == JOptionPane.YES_OPTION) {
            this.dispose();
            new GameStartFrame(); // 返回难度选择界面
        } else {
            System.exit(0);
        }
    }
}
